using System;
using System.Collections.Generic;
using System.Text;
using AF_ORM.CORE;
using System.Data;
using System.Data.SqlClient;
namespace Tongiao.Manager
{
                

    public class Tg_CategoryManager:Tongiao.ManagerBase.Tg_CategoryManagerBase
    {
            public static Tg_CategoryManager CreateInstant()
            {
                return new Tg_CategoryManager();
            }

            public DataTable getCategoryListByCatType(string CatType)
            {
                string strSql = "select C.*, C1.CatName  as CatNameChild, C1.Id as IdChild, C1.CatType as CatTypeChild, C1.OrderIndex as IndexChild,";
                strSql += " C1.CreatedDate as CreatedDateChild from tg_Category as C, tg_Category as C1 where C.CatType = '" + CatType + "'";
                strSql += " and C1.CatType = '" + CatType + "'";
                strSql += " and ((C.Parent is null or C.Parent = '00000000-0000-0000-0000-000000000000') or (C.Parent is not null and C.Parent != '00000000-0000-0000-0000-000000000000' and C1.Parent = C.Id )) and C1.Id <> C.Id ";
                return SqlHelper.ExecuteDataTable(Config.ConnectionConfig.ConnectionString,CommandType.Text,strSql);
            }

            public DataTable getAllCategoryListByCatType(string CatType)
            {
                string strSql = "select C.*, C1.CatName  as CatNameChild, C1.Id as IdChild, C1.CatType as CatTypeChild, C1.OrderIndex as IndexChild,";
                strSql += " C1.CreatedDate as CreatedDateChild from tg_Category as C inner join tg_Category as C1 on (C.Id = C1.Parent) where C.CatType = '" + CatType + "'";
                strSql += " and C1.CatType = '" + CatType + "' order by C.Id";
               
                return SqlHelper.ExecuteDataTable(Config.ConnectionConfig.ConnectionString, CommandType.Text, strSql);
            }

            public DataTable getListParentCat(string CatType)
            {
                string strSql = "select * from tg_Category where CatType = '" + CatType + "' and (Parent is null or Parent = '00000000-0000-0000-0000-000000000000')";
                return SqlHelper.ExecuteDataTable(Config.ConnectionConfig.ConnectionString, CommandType.Text,strSql);
            }
    }

    
}
                    
